<?php
require_once("./include/bm_config.php");
function downloads($file_dir, $tmp)
{
	if (!file_exists($file_dir.$tmp))
	{
		header("Content-type: text/html; charset=utf-8");
	    echo "<script language='javascript'>\n";
	    echo "alert('文件未找到');\n";
	    echo "history.go(-1);\n";
	    echo "</script>";
	    exit(0);
	} 
	else 
	{
		ob_end_clean();
		$file = fopen($file_dir.$tmp,"r"); 
		Header("Content-type: application/octet-stream; charset=utf-8");
		Header("Accept-Ranges: bytes");
		Header("Accept-Length: ".filesize($file_dir . $tmp));
		Header("Content-Disposition: attachment; filename=".$tmp);
		echo fread($file, filesize($file_dir.$tmp));
		fclose($file);
	}
}
if(isset($_GET['doc']))
{
	$doc_name=$_GET['doc'];//iconv("GBK", "UTF-8", urldecode($_GET['doc']));
	$tmp_doc_name = iconv("UTF-8", "GBK", $doc_name);
	$file_addr = $DOCUMENTS_FILE . $doc_name;
	downloads($DOCUMENTS_FILE, $tmp_doc_name);

}


else 
{
	require_once("./bm_footer.php");
    echo "<script language='javascript'>\n";
    echo "alert('这儿什么都没有~~');\n";
    echo "history.go(-1);\n";
    echo "</script>";
    exit(0);
}

?>
